﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using blacksoft.Models;

namespace blacksoft.Controllers
{
    public class OrdenCompraDetalleController : Controller
    {
        private inf245travelbusEntities db = new inf245travelbusEntities();

        // GET: /OrdenCompraDetalle/
        public ActionResult Index()
        {
            var detalle_ordencompra = db.Detalle_OrdenCompra.Include(d => d.OrdenCompra).Include(d => d.Producto);
            return View(detalle_ordencompra.ToList());
        }

        // GET: /OrdenCompraDetalle/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Detalle_OrdenCompra detalle_ordencompra = db.Detalle_OrdenCompra.Find(id);
            if (detalle_ordencompra == null)
            {
                return HttpNotFound();
            }
            return View(detalle_ordencompra);
        }

        // GET: /OrdenCompraDetalle/Create
        public ActionResult Create()
        {
            ViewBag.IDOrdenCompra = new SelectList(db.OrdenCompra, "IDOrdenCompra", "Estado");
            ViewBag.IDProducto = new SelectList(db.Producto, "IDProducto", "Nombre");
            return View();
        }

        // POST: /OrdenCompraDetalle/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include="IDOrdenCompra,IDProducto,Cantidad,Subtotal,PrecioUnitario,IDDetalle_OrdenCompra")] Detalle_OrdenCompra detalle_ordencompra)
        {
            if (ModelState.IsValid)
            {
                db.Detalle_OrdenCompra.Add(detalle_ordencompra);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.IDOrdenCompra = new SelectList(db.OrdenCompra, "IDOrdenCompra", "Estado", detalle_ordencompra.IDOrdenCompra);
            ViewBag.IDProducto = new SelectList(db.Producto, "IDProducto", "Nombre", detalle_ordencompra.IDProducto);
            return View(detalle_ordencompra);
        }

        // GET: /OrdenCompraDetalle/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Detalle_OrdenCompra detalle_ordencompra = db.Detalle_OrdenCompra.Find(id);
            if (detalle_ordencompra == null)
            {
                return HttpNotFound();
            }
            ViewBag.IDOrdenCompra = new SelectList(db.OrdenCompra, "IDOrdenCompra", "Estado", detalle_ordencompra.IDOrdenCompra);
            ViewBag.IDProducto = new SelectList(db.Producto, "IDProducto", "Nombre", detalle_ordencompra.IDProducto);
            return View(detalle_ordencompra);
        }

        // POST: /OrdenCompraDetalle/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include="IDOrdenCompra,IDProducto,Cantidad,Subtotal,PrecioUnitario,IDDetalle_OrdenCompra")] Detalle_OrdenCompra detalle_ordencompra)
        {
            if (ModelState.IsValid)
            {
                db.Entry(detalle_ordencompra).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.IDOrdenCompra = new SelectList(db.OrdenCompra, "IDOrdenCompra", "Estado", detalle_ordencompra.IDOrdenCompra);
            ViewBag.IDProducto = new SelectList(db.Producto, "IDProducto", "Nombre", detalle_ordencompra.IDProducto);
            return View(detalle_ordencompra);
        }

        // GET: /OrdenCompraDetalle/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Detalle_OrdenCompra detalle_ordencompra = db.Detalle_OrdenCompra.Find(id);
            if (detalle_ordencompra == null)
            {
                return HttpNotFound();
            }
            return View(detalle_ordencompra);
        }

        // POST: /OrdenCompraDetalle/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Detalle_OrdenCompra detalle_ordencompra = db.Detalle_OrdenCompra.Find(id);
            db.Detalle_OrdenCompra.Remove(detalle_ordencompra);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
